import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDArenaRobot {
	/**编号*/
	id,
	/**积分上限>*/
	scoreUp,
	/**玩家数量*/
	playerNum,
	/**基础关卡，配置数量大于5个*/
	stage,
	/**基础怪物，配置数量大于5个*/
	mosterid,
	/**怪物积分，配置数量大于5个*/
	score,

	/**枚举数量*/
	EnumCount
}



export class CDArenaRobot{
	/**编号*/
	public id: number;
	/**积分上限>*/
	public scoreUp: number;
	/**玩家数量*/
	public playerNum: number;
	/**基础关卡，配置数量大于5个*/
	public stage: number[];
	/**基础怪物，配置数量大于5个*/
	public mosterid: number[];
	/**怪物积分，配置数量大于5个*/
	public score: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDArenaRobot.id: return this.id;
			case E_CDArenaRobot.scoreUp: return this.scoreUp;
			case E_CDArenaRobot.playerNum: return this.playerNum;
			case E_CDArenaRobot.stage: return this.stage;
			case E_CDArenaRobot.mosterid: return this.mosterid;
			case E_CDArenaRobot.score: return this.score;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDArenaRobot.id: this.id = v; break;
			case E_CDArenaRobot.scoreUp: this.scoreUp = v; break;
			case E_CDArenaRobot.playerNum: this.playerNum = v; break;
			case E_CDArenaRobot.stage: this.stage = v; break;
			case E_CDArenaRobot.mosterid: this.mosterid = v; break;
			case E_CDArenaRobot.score: this.score = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDArenaRobot> = new HashMap<number, CDArenaRobot>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDArenaRobot[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDArenaRobot();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].scoreUp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].playerNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].stage = [];
			const attrArray = list[i].stage;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].mosterid = [];
			const attrArray = list[i].mosterid;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].score = [];
			const attrArray = list[i].score;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDArenaRobot{
		return this.datas ? this.datas.get(id) : null;
	}
}
